home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-05-01 | 2.7 KB | 141 lines | [TEXT/CWIE] |
- /*
- File: Offscreen.cp
-
- Contains: Class to help with offscreen drawing.
-
- Version: Appearance 1.0 SDK
-
- Copyright: © 1997 by Apple Computer, Inc., all rights reserved.
-
- File Ownership:
-
- DRI: Edward Voas
-
- Other Contact: 7 of 9, Borg Collective
-
- Technology: OS Technologies Group
-
- Writers:
-
- (edv) Ed Voas
-
- Change History (most recent first):
-
- <1> 9/11/97 edv First checked in.
- */
-
- #include "AppearanceSamplePrefix.h"
-
- #include <Appearance.h>
- #include "Offscreen.h"
-
- Offscreen::Offscreen()
- {
- fWorld = nil;
- fSavePort = nil;
- fSaveDevice = nil;
- SetRect( &fBounds, 0, 0, 0, 0 );
- }
-
- Offscreen::~Offscreen()
- {
- }
-
- void
- Offscreen::StartDrawing( const Rect& bounds, Boolean copyDest )
- {
- QDErr err;
- Rect globalRect;
- ThemeDrawingState state;
-
- fBounds = bounds;
-
- GetGWorld( &fSavePort, &fSaveDevice );
-
- globalRect = fBounds;
-
- LocalToGlobal( &topLeft( globalRect ) );
- LocalToGlobal( &botRight( globalRect ) );
-
- err = NewGWorld( &fWorld, 0, &globalRect, nil, nil, 0 );
- if ( err == noErr )
- {
- GetThemeDrawingState( &state );
- SetGWorld( fWorld, nil );
- SetOrigin( fBounds.left, fBounds.top );
- SetThemeDrawingState( state, true );
-
- LockPixels( GetGWorldPixMap( fWorld ) );
- EraseRect( &fBounds );
- TextFont( GetPortTextFont( fSavePort ) );
- TextSize( GetPortTextSize( fSavePort ) );
- TextFace( GetPortTextFace( fSavePort ) );
- TextMode( GetPortTextMode( fSavePort ) );
-
- if ( copyDest )
- {
- Rect portRect;
-
- GetPortBounds( fWorld, &portRect );
- CopyBits( (BitMap*)*GetPortPixMap( fSavePort ), (BitMap*)*GetPortPixMap( fWorld ),
- &fBounds, &portRect, srcCopy, nil );
- }
- }
- else
- fWorld = nil; // make sure
- }
-
- void
- Offscreen::EndDrawing()
- {
- ThemeDrawingState state;
- Rect portRect;
-
- if ( fWorld == nil ) return;
-
- SetOrigin( 0, 0 );
- SetGWorld( fSavePort, fSaveDevice );
-
- GetThemeDrawingState( &state );
- NormalizeThemeDrawingState();
-
- GetPortBounds( fWorld, &portRect );
- CopyBits( (BitMap*)*GetPortPixMap( fWorld ), (BitMap*)*GetPortPixMap( fSavePort ),
- &portRect, &fBounds, srcCopy, NULL );
-
- UnlockPixels( GetGWorldPixMap( fWorld ) );
- DisposeGWorld( fWorld );
-
- fWorld = nil;
-
- SetThemeDrawingState( state, true );
- }
-
- void
- Offscreen::EndDrawingAndBlend( const RGBColor& opColor )
- {
- ThemeDrawingState state;
- Rect portRect;
-
- if ( fWorld == nil ) return;
-
- SetOrigin( 0, 0 );
- SetGWorld( fSavePort, fSaveDevice );
-
- GetThemeDrawingState( &state );
- NormalizeThemeDrawingState();
-
- OpColor( &opColor );
- GetPortBounds( fWorld, &portRect );
- CopyBits( (BitMap*)*GetPortPixMap( fWorld ), (BitMap*)*GetPortPixMap( fSavePort ),
- &portRect, &fBounds, blend, NULL );
-
- UnlockPixels( GetGWorldPixMap( fWorld ) );
- DisposeGWorld( fWorld );
-
- fWorld = nil;
-
- SetThemeDrawingState( state, true );
- }
-
-